

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>Git版本控制系统 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-03-10 12:54" pubdate>
        2020年3月10日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      15
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">Git版本控制系统</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="Git"><a href="#Git" class="headerlink" title="Git"></a>Git</h2><p><img src="https://www.runoob.com/wp-content/uploads/2015/02/f7246b600c338744a9591cd7530fd9f9d62aa0f8.png" srcset="/img/loading.gif"></p>
<ul>
<li><p>概述</p>
<p>   目前世界上最先进的分布式版本控制系统。</p>
</li>
<li><p>版本控制系统 (Version Control System)</p>
<ul>
<li>记录一个文件或若干个文件的内容变化，以便将来查阅特定版本修订情况的系统。</li>
<li>还可以将文件回溯到之前的某个状态，可以从内容中看出是谁提交的代码出了问题。</li>
</ul>
</li>
<li><p>VCS的迭代 </p>
<p>   下面说一下VCS (版本控制系统) 的迭代</p>
<ul>
<li>本地版本控制系统 ,在本地上传，与维护。</li>
<li>集中的版本控制系统 （Centerolized Version Control System） 所有人上传到一个一个服务器上。</li>
<li>分布式版本控制系统 （Distributed Version Control System） 有一个本地服务器，还有一个远端服务器，这样数据不容易丢失。</li>
</ul>
</li>
</ul>
<ul>
<li>Git的特点<ul>
<li>只有在提交代码或拉取代码的时候需要网路</li>
<li>直接记录快照，而非差异比较</li>
<li>所有操作基本都在本地</li>
<li>保证完整性<br>Git 一般只添加数据用<ul>
<li>常规操作逻辑<br>file –&gt; 提交到暂存区 –&gt; 提交到本地仓库 –&gt; 提交到远程仓库<blockquote>
<p>&nbsp;&nbsp;提交到暂存区就是，当文件在移动过程中，会在暂存区保留一下，等提交完成后暂存区文件就没了。<br>&nbsp;&nbsp;比如 windows 移动文件时，从一个目录移动到另一个目录上，在移动过程中，会在本地生成一个保留文件，防止移动失败，导致数据丢失。</p>
</blockquote>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="git-安装"><a href="#git-安装" class="headerlink" title="git 安装"></a>git 安装</h2><ul>
<li><p>准备</p>
<table>
<thead>
<tr>
<th>linux主机</th>
<th>IP: 192.168.100.203</th>
</tr>
</thead>
</table>
<p>开启后运行以下命令:</p>
<pre><code class="hljs cmake">yum -y <span class="hljs-keyword">install</span> git <span class="hljs-comment"># 安装git</span></code></pre>
<p>创建Git仓库: </p>
<pre><code class="hljs awk">mkdir <span class="hljs-regexp">/tmp/</span>test <span class="hljs-comment"># 创建本地仓库目录</span>
</code></pre>

</li>
</ul>
<h2 id="Git仓库基本操作"><a href="#Git仓库基本操作" class="headerlink" title="Git仓库基本操作"></a>Git仓库基本操作</h2><ul>
<li>初始化仓库:<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># cd /tmp/test/
<span class="hljs-string">[root@localhost test]</span># git init # 初始化本地仓库
初始化空的 Git 版本库于 /tmp/test/.git/
<span class="hljs-string">[root@localhost test]</span># ll -la
总用量 <span class="hljs-number">4</span>
drwxr-xr-x.  <span class="hljs-number">3</span> root root   <span class="hljs-number">18</span> <span class="hljs-number">3</span>月  <span class="hljs-number">10</span> <span class="hljs-number">16</span>:<span class="hljs-number">26</span> .
drwxrwxrwt. <span class="hljs-number">14</span> root root <span class="hljs-number">4096</span> <span class="hljs-number">3</span>月  <span class="hljs-number">10</span> <span class="hljs-number">16</span>:<span class="hljs-number">26</span> ..
drwxr-xr-x.  <span class="hljs-number">7</span> root root  <span class="hljs-number">119</span> <span class="hljs-number">3</span>月  <span class="hljs-number">10</span> <span class="hljs-number">16</span>:<span class="hljs-number">26</span> .git # 目录里多出这个目录</code></pre></li>
<li>查看仓库状态<pre><code class="hljs vala">[root@localhost test]# git status # 查看仓库的状态
<span class="hljs-meta"># 位于分支 master</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># 初始提交</span>
<span class="hljs-meta">#</span>
无文件要提交（创建/拷贝文件并使用 <span class="hljs-string">&quot;git add&quot;</span> 建立跟踪）</code></pre></li>
<li>创建文件并保存到本地仓库:<pre><code class="hljs vala">[root@localhost test]# echo lmk &gt; hello.txt
[root@localhost test]# git add hello.txt # 将文件存储在暂存区
[root@localhost test]# git status # 查看仓库状态
<span class="hljs-meta"># 位于分支 master</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># 初始提交</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># 要提交的变更：</span>
<span class="hljs-meta">#   （使用 &quot;git rm --cached &lt;file&gt;...&quot; 撤出暂存区）</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta">#       新文件：    hello.txt</span>
<span class="hljs-meta">#</span>
[root@localhost test]# git commit -m <span class="hljs-string">&quot;first&quot;</span> # 将暂存区的文件存到本地仓库
<span class="hljs-meta"># 请为您的变更输入提交说明。以 &#x27;#&#x27; 开始的行将被忽略，而一个空的提交</span>
<span class="hljs-meta"># 说明将会终止提交。</span>
<span class="hljs-meta"># 位于分支 master</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># 初始提交</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># 要提交的变更：</span>
<span class="hljs-meta">#   （使用 &quot;git rm --cached &lt;file&gt;...&quot; 撤出暂存区）</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta">#       新文件：    hello.txt</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta"># -m 设置标签，用来分辨文件 </span>
<span class="hljs-meta"># &quot;first&quot; 标签名 随便填写</span></code></pre>
<pre><code class="hljs routeros"><span class="hljs-comment"># 用 commit 之前 必须声明用户名和邮箱，否则无法提交到本地仓库。</span>
[root@localhost test]# git<span class="hljs-built_in"> config </span>--global user.name <span class="hljs-string">&quot;k&quot;</span> # 设置用户名
[root@localhost test]# git<span class="hljs-built_in"> config </span>--global user.email  1248287831@qq.com # 设置邮箱名
设置完毕后，您可以用下面的命令来修正本次提交所使用的用户身份：

 git commit --amend --reset-author</code></pre></li>
<li>文件回溯: 在暂存区回溯<pre><code class="hljs autoit">[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># echo 111 &gt;&gt; hello.txt </span>
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># git add hello.txt</span>
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># git status </span>
<span class="hljs-meta"># 位于分支 master</span>
<span class="hljs-meta"># 要提交的变更：</span>
<span class="hljs-meta">#   (使用 <span class="hljs-string">&quot;git reset HEAD &lt;file&gt;...&quot;</span> 撤出暂存区)</span>
<span class="hljs-meta">#</span>
<span class="hljs-meta">#       修改：      hello.txt</span>
<span class="hljs-meta">#</span>
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># cat hello.txt </span>
lmk
<span class="hljs-number">111</span>
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># git reset HEAD hello.txt # 把文件撤出暂存区</span>
重置后撤出暂存区的变更：
M       hello.txt
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># git checkout -- hello.txt #返回hello.txt之前的内容</span>
[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># cat hello.txt </span>
lmk</code></pre></li>
<li>文件回溯: 在本地仓库回溯<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost test]</span># echo <span class="hljs-number">222</span> &gt;&gt; hello.txt 
<span class="hljs-string">[root@localhost test]</span># git add hello.txt # 加入暂存区
<span class="hljs-string">[root@localhost test]</span># git commit -m <span class="hljs-string">&quot;second&quot;</span> # 提交到本地仓库
<span class="hljs-string">[master 2164542]</span> second
 <span class="hljs-number">1</span> file changed, <span class="hljs-number">1</span> insertion(+)
<span class="hljs-string">[root@localhost test]</span># cat hello.txt 
lmk
<span class="hljs-number">222</span>
<span class="hljs-string">[root@localhost test]</span># git log # 查看提交日志
commit <span class="hljs-number">216454239076</span>b6b5637e013b7b701905c9fff5af # 提交ID
Author: k &lt;<span class="hljs-symbol">1248287831@</span>qq.com&gt;
Date:   Tue Mar <span class="hljs-number">10</span> <span class="hljs-number">16</span>:<span class="hljs-number">59</span>:<span class="hljs-number">19</span> <span class="hljs-number">2020</span> +<span class="hljs-number">0800</span> # 提交时间

    second # 提交标签 第二次提交的

commit c3b610c18e1a8815fe12b051afe5ecd9c1061db2 # 提交ID
Author: k &lt;<span class="hljs-symbol">1248287831@</span>qq.com&gt;
Date:   Tue Mar <span class="hljs-number">10</span> <span class="hljs-number">16</span>:<span class="hljs-number">41</span>:<span class="hljs-number">25</span> <span class="hljs-number">2020</span> +<span class="hljs-number">0800</span> # 提交时间

    first # 提交标签 第一次提交的
<span class="hljs-string">[root@localhost test]</span># git reset --hard c3b610c18e1a8815fe12b051afe5ecd9c1061db2 # 指定first的commit信息,回溯到first状态
HEAD 现在位于 c3b610c first
<span class="hljs-string">[root@localhost test]</span># cat hello.txt 
lmk</code></pre>
<h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2>这章先写到这里，继续往下写的话有点多了，和看笔记没什么区别，下一章写，git远程仓库:<ul>
<li>github</li>
<li>gitlab</li>
</ul>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84/">微服务架构</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Git/">Git</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/03/10/Github%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Github远程仓库</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/03/08/hexo%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">
                        <span class="hidden-mobile">hexo博客搭建</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Git版本控制系统&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
